#include "highscores.h"

//saves HighScore to Highscore.txt file
void HighScores::save()
{
    sort(scores.end(), scores.begin());
    ofstream outfile("HighScore.txt");
    if (!outfile){
        cout <<"unable to open file ... I'm OUT!!!\n";
        exit(1);
    }
    for (auto it = scores.begin(); it != scores.end(); ++it)
    {
        outfile << *it << endl;
    }
    outfile.close();
}
//loads HighScore to HighScore object
void HighScores::load()
{
    ifstream infile("HighScore.txt");
    if (!infile){
        cout << "Unable to open file ... bailing out\n";
        exit(1);
    }
    string line;
    int curline = 0;
    getline(infile,line);
    while (infile){
        scores.push_back(stoi(line));
        curline++;
        getline(infile,line);
    }

    infile.close();
}

